package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        //构造器第1个参数为流,第2个参数可以传入boolean类型的数据来表示是否打开自动刷新供能
        PrintWriter pw = new PrintWriter(bw);

        Scanner scan = new Scanner(System.in);
        System.out.println("请开始输入内容,单独输入exit时推出");
        while (true){
            String line = scan.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);
            pw.flush();
        }
        pw.close();
    }
}
